import { NotFound } from 'lin-mizar';
import { FlowModel } from '../model/flow';

class Flow {
  static async createFlow(v) {
    const res = await FlowModel.create({
      index: v.get('body.index'),
      type: v.get('body.type'),
      art_id: v.get('body.art_id'),
      status: v.get('body.status'),
    })
    return res;
  }

  static async editFlow(id, index, type, art_id, status) {
    const flow = await FlowModel.findByPk(id)
    if (!flow) {
      throw new NotFound()
    }
    await flow.update({ index, type, art_id, status })
  }
  
  static async deleteFlow(id) {
    const flow = await FlowModel.findByPk(id)
    if (!flow) {
      throw new NotFound()
    }
    await flow.destroy()
  }

  static async getFlowList() {
    const res = await FlowModel.findAll({
      order: ['index']
    })
    return res;
  }

}

export { Flow as FlowDao }